#include "TimeIntegrator.h"

class TimeIntegratorFactory{
public:
    static TimeIntegratorFactory *GetInstance(){
        static TimeIntegratorFactory instance;
        return &instance;
    }
    bool Register(const std::string &id, CreateFn creator){
        return m_map.insert(TimeIntegratorFactoryMap::value_type(id,creator)).second;
    }
    bool Unregister(const std::string& id){
        return m_map.erase(id) == 1;
    }
    TimeIntegrator* CreateObject(const std::string& id){
        TimeIntegratorFactoryMap::iterator i = m_map.find(id);
        if(i != m_map.end()){
            return (i->second)();
        }
        std::cout << "Input Error! No found for " << id << std::endl;
        exit(0);
    }
    ~TimeIntegratorFactory(){ m_map.clear();}
private:
    typedef std::map<std::string, CreateFn> TimeIntegratorFactoryMap;
    TimeIntegratorFactoryMap m_map;
};
        
    
